# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=retire
_pkgname=retire.js
pkgver=5.4.0.r1.g3b01791
pkgrel=1
pkgdesc='Scanner detecting the use of JavaScript libraries with known vulnerabilities.'
arch=('any')
groups=('blackarch' 'blackarch-scanner' 'blackarch-code-audit')
url='http://retirejs.github.io/retire.js/'
license=('Apache')
depends=('nodejs')
makedepends=('npm' 'git')
source=("git+https://github.com/RetireJS/$_pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $_pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $_pkgname

  _npmdir="$pkgdir/usr/lib/node_modules/"

  install -dm 755 "$_npmdir"

  cd "$_npmdir"

  npm install --user root -g --prefix "$pkgdir/usr" "$pkgname@"
  rm -rf "$_npmdir/root"

  cd "$srcdir/$_pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" node/README.md
  install -Dm 644 LICENSE.md "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

